package ch.repit.aglaja.server.contacts;

import ch.repit.rwt.client.ContentTypeFamily;
import ch.repit.rwt.server.file.FileHolder;
import ch.repit.rwt.server.persistence.BaseDataObject;
import ch.repit.rwt.server.user.UserPhoto;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.Inheritance;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;

/**
 *
 * @author tc149752
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION)
@Inheritance(customStrategy = "complete-table")
public class Person extends BaseDataObject implements FileHolder {

    @Persistent
    private String firstName;
    @Persistent
    private String lastName;
    @Persistent
    private Boolean maleGender;
    @Persistent
    private String email;
    @Persistent
    private String mobilePhone;
    @Persistent
    private String profPhone;
    @Persistent
    private Integer dateOfBirth;

    @Persistent
    private String householdRef;

    // photos
    @Persistent
    private UserPhoto userPhoto;
    
    // constructor for creates
    public Person() { }

    public Integer getDateOfBirth() {
        return dateOfBirth;
    }

    public void setDateOfBirth(Integer dateOfBirth) {
        this.dateOfBirth = dateOfBirth;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public Boolean isMaleGender() {
        return maleGender;
    }

    public void setMaleGender(Boolean maleGender) {
        this.maleGender = maleGender;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getMobilePhone() {
        return mobilePhone;
    }

    public void setMobilePhone(String mobilePhone) {
        this.mobilePhone = mobilePhone;
    }

    public String getProfPhone() {
        return profPhone;
    }

    public void setProfPhone(String profPhone) {
        this.profPhone = profPhone;
    }


    public String getHouseholdRef() {
        return householdRef;
    }

    public void setHouseholdRef(String householdRef) {
        this.householdRef = householdRef;
    }

    public List<UserPhoto> getFiles() {
        List<UserPhoto> result = new ArrayList<UserPhoto>();
        if (userPhoto != null && userPhoto.getFileKey() != null)
            result.add(userPhoto);
        return result;
    }

    public UserPhoto createFileInstance() {
        if (userPhoto == null)
            userPhoto = new UserPhoto(); 
        return userPhoto;
    }


    private transient Set<ContentTypeFamily> allowedFileTypes = null;

    public Set<ContentTypeFamily> listAllowedFileTypes() {
        if (allowedFileTypes == null || allowedFileTypes.size() == 0) {
            allowedFileTypes = new HashSet<ContentTypeFamily>();
            allowedFileTypes.add(ContentTypeFamily.IMAGE);
        }
        return allowedFileTypes;
    }

    public int getImagePreviewSize() {
        return 50;
    }

    public long getFileMaxSizeInBytes() {
        return 500000;
    }

}
